package com.itbour.service.tg.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.dao.tg.SaleRankInfoDao;
import com.itbour.dto.tg.PartnerSaleDto;
import com.itbour.service.tg.SaleRankInfoService;

/**获取销售排行
 * @author LQ
 */
public class SaleRankInfoServiceImpl implements SaleRankInfoService {
	private SaleRankInfoDao saleRankInfoDao;
	
	public Page getPartnerSaleRank(Map<String, Object> parm, Integer pageNo,
			Integer pageSize) {
		Page result = null;
		try{
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = saleRankInfoDao.getPartnerSaleCnt(parm);
			while(totalSize >0 && totalSize <= skipResults){//当记录总数 小于 起始位置数
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			parm.put("pageSize", pageSize);
			parm.put("skipResults", skipResults);
			List<PartnerSaleDto> list=new ArrayList<PartnerSaleDto>();
			list=saleRankInfoDao.getPartnerSaleInfo(parm);
			result = new JspPage(skipResults, totalSize, pageSize, list);
		}catch(Exception e){
			System.out.println(e.getMessage());
		}
		return result;
	}

	
	
	
	public SaleRankInfoDao getSaleRankInfoDao() {
		return saleRankInfoDao;
	}
	public void setSaleRankInfoDao(SaleRankInfoDao saleRankInfoDao) {
		this.saleRankInfoDao = saleRankInfoDao;
	}
}
